home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / cursors.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  7KB  |  291 lines

  1. /*
  2.  * $Id: cursors.c,v 0.91 1994/02/20 00:53:29 zhao Pre-Release $
  3.  *
  4.  *. This file is part of BIT shareware package. After the two weeks of
  5.  *  free evaluation period, you are encouraged (required) to register
  6.  *  your copy for a small registration fee, which is $35 for personal use
  7.  *  and $50 for commercial, government and institutional use.
  8.  *
  9.  *  Copyright(c) 1993, 1994 by T.C. Zhao.
  10.  *  All rights reserved.
  11.  *
  12.  *  Permission to use, copy, and distribute this software in its entirety
  13.  *  for non-commercial purposes is hereby granted, provided that the
  14.  *  above shareware and copyright notices and this permission notice
  15.  *  appear in all copies and their documentation.
  16.  *
  17.  *  This software may be modified for your own use, but modified versions
  18.  *  may not be distributed without prior consent of the author.
  19.  *
  20.  *  This software is provided "as is" without expressed or implied
  21.  *  warranty of any kind.
  22.  *
  23.  *.
  24.  *
  25.  *  All cursor definations
  26.  */
  27. #if !defined(lint) && defined(F_ID)
  28. char *id_curs = "$Id: cursors.c,v 0.91 1994/02/20 00:53:29 zhao Pre-Release $";
  29. #endif
  30.  
  31. #include <stdio.h>
  32. #include "ulib.h"
  33. #include "gl/gl.h"
  34. #include "curdef.h"
  35.  
  36. extern int is_valid_win(long);
  37. extern void set_current_window(long);
  38.  
  39. #include "bitmaps/sfrect.cur"
  40. #include "bitmaps/rect10.cur"
  41. #include "bitmaps/rect20.cur"
  42. #include "bitmaps/rect30.cur"
  43. #include "bitmaps/scross.cur"
  44. #include "bitmaps/rotate.cur"
  45. #include "bitmaps/rslant.cur"
  46. #include "bitmaps/lslant.cur"
  47. #include "bitmaps/busy.cur"
  48. #include "bitmaps/hand.cur"
  49. #include "bitmaps/sdisk.cur"
  50. #include "bitmaps/hline.cur"
  51. #include "bitmaps/vline.cur"
  52. #include "bitmaps/circ10.cur"
  53. #include "bitmaps/circ20.cur"
  54. #include "bitmaps/circ30.cur"
  55. #include "bitmaps/circnet.cur"
  56.  
  57. typedef struct
  58.   {
  59.       unsigned short *curbits;
  60.       Cur_name name;
  61.       int type;
  62.       int hotx, hoty;
  63.   }
  64. cur_def_t;
  65.  
  66.  
  67. static cur_def_t bit_cursors[] =
  68. {
  69.     {0, CUR_DEFAULT, C16X1, 8, 8},
  70.     {cur_scross, CUR_S_CROSS, C16X1, 8, 8},
  71.     {cur_busy, CUR_BUSY, C16X2, 8, 8},
  72.     {cur_hand, CUR_HAND, C16X2, 2, 10},
  73.     {cur_sfrect, CUR_S_FRECT, C16X1, 7, 7},
  74.     {cur_rect10, CUR_RECT10, C16X1, 7, 7},
  75.     {cur_rect20, CUR_RECT20, C32X1, 15, 15},
  76.     {cur_rect30, CUR_RECT30, C32X1, 15, 15},
  77.     {cur_lslant, CUR_L_LINE, C16X1, 7, 7},
  78.     {cur_rslant, CUR_R_LINE, C16X1, 7, 7},
  79.     {cur_sdisk, CUR_S_DISK, C16X1, 7, 7},
  80.     {cur_rot1, CUR_ROT1, C16X2, 8, 8},
  81.     {cur_rot2, CUR_ROT2, C16X2, 8, 8},
  82.     {cur_rot3, CUR_ROT3, C16X2, 8, 8},
  83.     {cur_rot4, CUR_ROT4, C16X2, 8, 8},
  84.     {cur_hline, CUR_H_LINE, C16X1, 8, 8},
  85.     {cur_vline, CUR_V_LINE, C16X1, 8, 8},
  86.     {cur_circ10, CUR_CIRC10, C16X1, 7, 7},
  87.     {cur_circ20, CUR_CIRC20, C32X1, 15, 15},
  88.     {cur_circ30, CUR_CIRC30, C32X1, 15, 15},
  89.     {cur_circnet, CUR_CIRCNET, C32X1, 15, 15},
  90.  
  91. };
  92.  
  93. static int ncursors = sizeof(bit_cursors) / sizeof(bit_cursors[0]);
  94.  
  95. /********************************************************************
  96.  * Initialize all cursors
  97.  ********************************************************************/
  98.  
  99. void
  100. init_cursor(void)
  101. {
  102.     static int cur_init;
  103.     int mcol;
  104.     cur_def_t *curs = bit_cursors + 1, *curs_end = bit_cursors + ncursors;
  105.  
  106.     if (cur_init)
  107.     return;
  108.  
  109.     /* multi-colored cursor supported ? */
  110.     mcol = getgdesc(GD_BITS_CURSOR) > 1;
  111.  
  112.     drawmode(CURSORDRAW);
  113.  
  114.     mapcolor(2, 255, 255, 255);
  115.  
  116.     for (; curs < curs_end; curs++)
  117.       {
  118.       curstype(curs->type);
  119.       defcursor(curs->name, curs->curbits);
  120.       curorigin(curs->name, curs->hotx, curs->hoty);
  121.       }
  122.  
  123.     drawmode(NORMALDRAW);
  124. }
  125.  
  126. /*****************************************************************
  127.  * Get current cursor index
  128.  ****************************************************************/
  129. static int
  130. get_cursor(void)
  131. {
  132.     short ci;
  133.     Colorindex g1, g2;
  134.     Boolean b;
  135.  
  136.     getcursor(&ci, &g1, &g2, &b);
  137.     return ci;
  138. }
  139.  
  140. void
  141. set_cursor(long win, int n)
  142. {
  143.     if (n >= 0 && win > 0)
  144.       {
  145.       set_current_window(win);
  146.       if (get_cursor() != n)
  147.           setcursor(n, 1, 0);
  148.       }
  149. }
  150.  
  151. /**********************************************************************
  152.  *  Default cursors for windows that have a fixed durations
  153.  *  or windows whose default cursor is different from that of the
  154.  *  system
  155.  **********************************************************************/
  156.  
  157. #define MAXFCUR 8
  158.  
  159. static struct Fixcur
  160. {
  161.     long wid;
  162.     int cnum;
  163. }
  164. fixcur[MAXFCUR];
  165.  
  166. void
  167. set_default_cursor(long win, int n)
  168. {
  169.     struct Fixcur *fc = fixcur + MAXFCUR;
  170.  
  171.     /* search for availabel slots */
  172.     while (--fc >= fixcur && fc->wid != win && is_valid_win(fc->wid))
  173.     ;
  174.  
  175.     if (fc < fixcur)
  176.       {
  177.       M_warn("DefCursor", "Unable to set cursor for Wid=%ld", win);
  178.       return;
  179.       }
  180.  
  181.     fc->wid = win;
  182.     fc->cnum = n;
  183. }
  184.  
  185. /***********************************************************************
  186.  * Set the curosr to default, either the one  set by set_cursor_default,
  187.  * or system default if none is set
  188.  **********************************************************************/
  189. void
  190. reset_cursor(long win)
  191. {
  192.     struct Fixcur *fc = fixcur + MAXFCUR;
  193.     int n;
  194.  
  195.     if (win <= 0)
  196.     return;            /* need this check */
  197.  
  198.     while (--fc >= fixcur && win - fc->wid)
  199.     ;
  200.  
  201.     n = (fc < fixcur) ? CUR_DEFAULT : fc->cnum;
  202.     set_cursor(win, n);
  203. }
  204.  
  205. /*************************************************************************
  206.  * misc. cursor routines
  207.  ***********************************************************************/
  208.  
  209. /******* Change cursor color: index 1 only ***************/
  210. void
  211. set_cursor_color(int *c)
  212. {
  213.     drawmode(CURSORDRAW);
  214.     mapcolor(1, c[0], c[1], c[2]);
  215.     drawmode(NORMALDRAW);
  216. }
  217.  
  218. void
  219. get_cursor_color(int *c)
  220. {
  221.     short cs[3];
  222.     drawmode(CURSORDRAW);
  223.     getmcolor(1, cs, cs + 1, cs + 2);
  224.     drawmode(NORMALDRAW);
  225.     c[0] = cs[0];
  226.     c[1] = cs[1];
  227.     c[2] = cs[2];
  228. }
  229.  
  230.  
  231. int
  232. rotate_circle_cursor(long win)
  233. {
  234.     static int cur_cur;
  235.     cur_cur++;
  236.     if ((cur_cur < CUR_ROT1) || (cur_cur > CUR_ROT4))
  237.     cur_cur = CUR_ROT1;
  238.     set_cursor(win, cur_cur);
  239.     return cur_cur;
  240. }
  241.  
  242. #if 0                /* Not finished yet *{* */
  243. /* set (15-x)'s bit to 1: short counts from zero, but cursor defines
  244.  *  coutns from bit 15
  245.  */
  246. #define set_bit(s, x)  ((s) |= (1 << (15-(x))))
  247.  
  248. /*** Make specialized cursors on the fly ***/
  249. int
  250. make_cursor(int type, int size)
  251. {
  252.     static unsigned short cur_defs[2 * 32];
  253.     static int nextcn = CUR_FREE1;
  254.     int i, cn, off1;
  255.  
  256.     cn = nextcn;
  257.  
  258.     if (size > 32)
  259.     size = 32;
  260.  
  261.     for (i = 0; i < 32; i += 2)
  262.     cur_defs[i] = cur_defs[i + 1] = 0;
  263.  
  264.     off1 = (32 - size) / 2;
  265.  
  266.     switch (type)
  267.       {
  268.       case FREE_L_SLANT:
  269.       default:
  270.       fprintf(stderr, "size=%d off1=%d\n", size, off1);
  271.       for (i = off1; i < off1 + size; i++)
  272.         {
  273.         if (i < 16)
  274.             set_bit(cur_defs[i * 2], i);
  275.         else
  276.             set_bit(cur_defs[i * 2 + 1], i - 16);
  277.         }
  278.       break;
  279.       }
  280.  
  281.     /* define this cursor */
  282.     curstype(C32X1);
  283.     defcursor(cn, cur_defs);
  284.     curorigin(cn, 15, 15);
  285.  
  286.     /* alternate between free1 & free2 */
  287.     nextcn = (cn == CUR_FREE1) ? CUR_FREE2 : CUR_FREE1;
  288.     return cn;
  289. }
  290. #endif /*** } **/
  291.